package com.yeyks.controller;

import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.constants.OrderStatus;
import com.yeyks.commonReference.append.sms.SmsService;
import com.yeyks.commonReference.service.account.AccountCommissionService;
import com.yeyks.commonReference.service.order.OrderHeadService;
import com.yeyks.commonReference.service.user.UserCommissionService;
import com.yeyks.order.dal.domain.OrderHead;
import com.yeyks.task.OrderCompleteTask;
import com.yeyks.task.RoomTask;
import com.yeyks.task.UserMakerTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;

@Api(tags = "测试接口")
//@ApiIgnore
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {
    @Autowired
    private OrderCompleteTask orderCompleteTask;
    @Autowired
    private UserCommissionService userCommissionService;
    @Autowired
    private RoomTask roomTask;
    @Autowired
    private OrderHeadService orderHeadService;
    @Autowired
    private AccountCommissionService accountCommissionService;
    @Autowired
    private SmsService smsService;
    @Autowired
    private UserMakerTask userMakerTask;

    @ApiIgnore
    @ApiOperation("测试：小vip佣金入账")
    @PostMapping("/mini/vip/commission")
    public AjaxResponseBody setMiniVipCommission(String orderNo) {
        OrderHead byOrderNo = orderHeadService.getByOrderNo(orderNo);
        Arguments.beanIsNull(byOrderNo, "该订单不存在");
        if (OrderStatus.postCheckOut.equals(byOrderNo.getStatus())) {
            return AjaxResponseBody.success(true);
        }
        accountCommissionService.setMiniVipCommission(byOrderNo);
        return AjaxResponseBody.success(true);
    }

    @ApiOperation("测试：修改订单完成")
    @PostMapping("/order/complete")
    public AjaxResponseBody orderComplete() {
        orderCompleteTask.orderComplete();
        return AjaxResponseBody.success(true);
    }

    @ApiIgnore
    @ApiOperation("测试：订单7天内下单佣金")
    @PostMapping("/order/seven/commission")
    public AjaxResponseBody orderSevenCommission(String orderNo) {
        OrderHead byOrderNo = orderHeadService.getByOrderNo(orderNo);
        Arguments.beanIsNull(byOrderNo, "订单不存在");
        userCommissionService.addZeroAmount(byOrderNo);
        return AjaxResponseBody.success(true);
    }

    @ApiIgnore
    @ApiOperation("测试：测试生成优享房态")
    @PostMapping("/order/jip")
    public AjaxResponseBody initJipCalendar() {
        roomTask.createRoomCalendarJipInfo();
        return AjaxResponseBody.success(true);
    }

    @ApiIgnore
    @ApiOperation("测试：0元推广订单分佣")
    @PostMapping("/zero/commission")
    public AjaxResponseBody zeroCommission() {
        OrderHead orderHead = new OrderHead();
        orderHead.setUserId(263);
        orderHead.setGmtCreate(new Date());
        userCommissionService.addZeroAmount(orderHead);
        return AjaxResponseBody.success(true);
    }

//    @ApiIgnore
//    @ApiOperation("测试：新手任务奖励")
//    @PostMapping("/new/user/task")
//    public AjaxResponseBody newUserTask() {
//        OrderHead orderHead = new OrderHead();
//        orderHead.setUserId(263).setSnapshotTotalFee(30000);
//        userCommissionService.addC2bNewUserTaskAmount(orderHead);
//        return AjaxResponseBody.success(true);
//    }

    @ApiIgnore
    @ApiOperation("测试：新手任务奖励")
    @PostMapping("/new/user/task")
    public AjaxResponseBody newUserTask(Integer userId, Integer total) {
        if (userId == null) {
            userId = 263;
        }
        if (total == null) {
            total = 30000;
        }
        orderCompleteTask.updateTask(userId, "15188445491", total);
        return AjaxResponseBody.success(true);
    }

    @ApiIgnore
    @ApiOperation("测试：新手任务奖励")
    @PostMapping("/new/user/task/sms")
    public AjaxResponseBody newUserTaskSms() {
        return AjaxResponseBody.success(smsService.sendNewTask("15188445491", 300));
    }

    @ApiOperation("测试：发创客奖金")
    @PostMapping("UserMakerTask")
    public AjaxResponseBody UserMakerTask() {
        userMakerTask.fajiangjinScheduled();
        return AjaxResponseBody.success(true);
    }

}
